import request from "../utils/request";
import type {
  RegisterParams,
  RegisterRes,
  LoginByPhoneParams,
  LoginByPhoneRes,
  SendValidateCodeRes,
  GetLoginUserInfoRes,
  LoginByAppParams,
  RegisterUserInfoRes
} from "@/types/user";
/**
 * 注册接口controller
 * @param {object} params UserRegisterDto
 * @param {string} params.code
 * @param {string} params.phone
 * @returns
 */
export function register(params: RegisterParams) {
  return request.post<any, RegisterRes>(`/api/u-center/register`, params);
}


export function registerUserInfo(params: RegisterUserInfoRes) {
  return request.post<any, RegisterRes>(`/api/u-center/register-user`, params);
}

/**
 * 获取未读消息以及消息的列表
 */
export function messageList() {
  return request.get<any, any>(`/api/u-center/get-message-list`);
}

export function updateMessageStatus(msgId: any) {
  return request.post<any, any>(`/api/u-center/updateMessageStatus/${msgId}`);
}

/**
 * 获取首页未读取消息的数量
 */
export function getHomeMessageNotReadApi() {
  return request.get<any, any>(`/api/u-center/getHomeMessageNotRead`);
}


/**
 * 手机号登录
 * @param {object} params LoginUserDto
 * @param {string} params.code
 * @param {string} params.password
 * @param {string} params.phone
 * @param {string} params.username
 * @returns
 */
export function loginByPhone(params: LoginByPhoneParams) {
  return request.post<any, LoginByPhoneRes>(
    `/api/u-center/login/byPhone`,
    params
  );
}
/**
 * 邮箱登录
 * @param {object} params LoginUserDto
 * @param {string} params.code
 * @param {string} params.password
 * @param {string} params.phone
 * @param {string} params.username
 * @returns
 */
export function loginByMail(params: any) {
  return request.post<any, any>(
    `/api/u-center/login/byMail`,
    params
  );
}

/**
 * 发送短信验证码接口
 * @param {string} phone 手机号
 * @returns
 */
export function sendValidateCode(phone: string) {
  return request.get<any, SendValidateCodeRes>(
    `/api/u-center/getCode/${phone}`
  );
}

/**
 * 获取用户信息
 * @returns
 */
export function getLoginUserInfo() {
  return request.get<GetLoginUserInfoRes>(`/api/u-center/getLoginUserInfo`);
}

/**
 * 验证身份（1手机2邮箱3密码验证）
 * @param {string} type type
 * @param {string} checkCode checkCode
 * @returns
 */

export function checkIdentity(type: string, checkCode: string) {
  return request.post<CheckIdentityParams>(
    `/api/u-center/check/ident?type=${type}&checkCode=${checkCode}`
  );
}
export interface CheckIdentityParams {
  code: number;
}

// 参数接口
export interface EditUserInfoParams {
  account?: string;
  avatar?: string;
  contact?: string;
  degree?: string;
  graduateTime?: Record<string, unknown>;
  matriculationTime?: Record<string, unknown>;
  name?: string;
  nickName?: string;
  password?: string;
  phone?: string;
  rePassword?: string;
  school?: string;
  sex?: number;
  signature?: string;
  specialized?: string;
  status?: number;
}

/**
 * 编辑个人基本信息
 * @param {object} params UserInfoDto
 * @param {string} params.account
 * @param {string} params.avatar
 * @param {string} params.contact
 * @param {string} params.degree
 * @param {object} params.graduateTime
 * @param {object} params.matriculationTime
 * @param {string} params.name
 * @param {string} params.nickName
 * @param {string} params.password
 * @param {string} params.phone
 * @param {string} params.rePassword
 * @param {string} params.school
 * @param {number} params.sex
 * @param {string} params.signature
 * @param {string} params.specialized
 * @param {number} params.status
 * @returns
 */
export function editUserInfo(params: EditUserInfoParams) {
  return request.post<{ code: number }>(`/api/u-center/edit`, params);
}
export function editUserimpifmInfo(params: any) {
  return request.post<{ code: number }>(`/api/u-center/edit/changeimpifm`, params);
}

/**
 * 账号密码登录
 * @param {object} params LoginUserDto
 * @param {string} params.code
 * @param {string} params.password
 * @param {string} params.phoneOrEmail
 * @returns
 */
export function passwordLogin(params: LoginByAppParams) {
  return request.post(`/api/u-center/login/byApp`, params);
}

// 参数接口
export interface EmailReisterParams {
  code: string;
  email: string;
}

// 响应接口
export interface EmailReisterRes {
  code: number;
  data: string;
  msg: string;
}

/**
 * 邮箱注册
 * @param {object} params UserEmailRegisterDto
 * @param {string} params.code
 * @param {string} params.email
 * @returns
 */
export function emailReister(params: EmailReisterParams) {
  return request.post<EmailReisterRes>(`/api/u-center/email-register`, params);
}

// 响应接口
export interface SendEmailValidateCodeRes { }

/** 
 * 发送邮箱验证码接口
 * @param {string} mail 邮箱
  * @returns
 */
export function sendEmailValidateCode(mail: string) {
  return request.get<SendEmailValidateCodeRes>(`/api/u-center/getEmailCode/${mail}`);
}
export function userCheckInsert(param: any) {
  return request.post<any>(`/api/u-apply`, param);
}
export function userCheckUpdate(param: any) {
  return request.put<any>(`/api/u-apply`, param);
}
export function userCheckGet() {
  return request.get<any>(`/api/u-apply`);
}
/**
 * 获取报名信息
 */
export function getApplyInfo(id: string, type: number) {
  return request.get<any>(`/api/u-center/go-on-apply/${id}/${type}`);
}